package org.kumas.sgrpc.remoting.exchange;

import org.kumas.sgrpc.common.extension.ExtensionLoader;

public class Exchanger$Adaptive implements org.kumas.sgrpc.remoting.exchange.Exchanger {

    public org.kumas.sgrpc.remoting.exchange.ExchangeClient connect(org.kumas.sgrpc.common.URL arg0,
        org.kumas.sgrpc.remoting.exchange.ExchangeHandler arg1)
        throws org.kumas.sgrpc.remoting.RemotingException {
        if (arg0 == null) {
            throw new IllegalArgumentException("url == null");
        }
        org.kumas.sgrpc.common.URL url = arg0;
        String extName = url.getParameter("exchanger", "HeaderExchanger");
        if (extName == null) {
            throw new IllegalStateException(
                "Failed to get extension (org.kumas.sgrpc.remoting.exchange.Exchanger) name from url ("
                    + url.toString() + ") use keys([exchanger])");
        }
        org.kumas.sgrpc.remoting.exchange.Exchanger extension = (org.kumas.sgrpc.remoting.exchange.Exchanger) ExtensionLoader
            .getExtensionLoader(org.kumas.sgrpc.remoting.exchange.Exchanger.class)
            .getExtension(extName);
        return extension.connect(arg0, arg1);
    }

    public org.kumas.sgrpc.remoting.exchange.ExchangeServer bind(org.kumas.sgrpc.common.URL arg0,
        org.kumas.sgrpc.remoting.exchange.ExchangeHandler arg1)
        throws org.kumas.sgrpc.remoting.RemotingException {
        if (arg0 == null) {
            throw new IllegalArgumentException("url == null");
        }
        org.kumas.sgrpc.common.URL url = arg0;
        String extName = url.getParameter("exchanger", "HeaderExchanger");
        if (extName == null) {
            throw new IllegalStateException(
                "Failed to get extension (org.kumas.sgrpc.remoting.exchange.Exchanger) name from url ("
                    + url.toString() + ") use keys([exchanger])");
        }
        org.kumas.sgrpc.remoting.exchange.Exchanger extension = (org.kumas.sgrpc.remoting.exchange.Exchanger) ExtensionLoader
            .getExtensionLoader(org.kumas.sgrpc.remoting.exchange.Exchanger.class)
            .getExtension(extName);
        return extension.bind(arg0, arg1);
    }
}